function [report,flags]=reportCheck(report,model,parVec,flags,sampleStru)

%% I. Inputs
%
%% I.a) *report* structure can contain following fields
%
% 1) *.stateMom*, will be usded for all moments (stds and cross-correlations)
% including variance decompositions, and also Historical Decompositions
%
% 2) *.stateIRF*, Impulse responses. Can be of the form <name> + 'lev',
% which indicates IRF should be added.
%
% 3) *.stateSpectrum*  only for the spectral decomposition. Can also
% contain <name> + 'lev'.
%
% 4) *.subSamples* [NB NC] cell array with dates at which the sub-samples
% start in column 1 and subsample ends in column 2. Leave empty if there
% are no subsamples. This will be used in the historical analysis to zoom
% into particular episodes.
%
% 5) *.stateDecomp* cell with the states that will be decomposed
%
%% I.b) *model* structure must contain *.handle*, *.solveOptions*, *addsol*
%
%% I.c) parvec: full parameter vector to solve model
%
%% I.d) flags: structure with flags.changeHandle
%
%% I.e) *sampleStru* must contain *.sampleVec*
%
%% II. Output
%
%% II.a) Append to report
%
% < >Pos with row Position of each element
%
%% If subSamples, also assign
%
% *.subSampleN:* [NB 1] vector with the lengths of the sub-samples
%
% *.subSamplePos:* [NB 2] matrix with the position at which each sample
%  begings and ends
%
% *.subSampleCell:* [NB 1] cell with the names of the subsamples in string
%  form

%% I) Solve model and extract state names
if flags.changeHandle==false;
    tempHandle=model.handle;
else
    tempHandle=str2func([func2str(model.handle),model.add2Handle]);
end

[GG,RR,C,eu,SDX,ZZ,initss,ssvec,flag,ssnames,stateNames,shockNames]...
    =feval(tempHandle,parVec,model.solveOptions,model.addsol);


%% *report*
%
%% 1. stateDecomp
disp('Checking if requested report.stateDecomp');
if isfield(report,'stateDecomp')==false || isempty(report.stateDecomp);
    disp('No States to decompose');
    flags.stateDecomp=false;
else
    disp('States to Decompose');
    printcell(report.stateDecomp(:));
    report.stateDecompPos=cellposition(report.stateDecomp(:),stateNames,1);
    flags.stateDecomp=true;
    if flags.onscreen==1;
        quer('c');
    end
end

%% 2. stateSpectrum
disp('Checking if requested report.stateSpectrum');
if isfield(report,'stateSpectrum')==false || isempty(report.stateSpectrum);
    disp('No States for Spectrum');
    flags.stateSpectrum=false;
else
    disp('States to for Spectrum');
    printcell(report.stateSpectrum(:));
    [tempPos,tempAdd]=extractlevels(report.stateSpectrum,stateNames);
    report.stateSpectrumPos=tempPos;
    report.stateSpectrumPosAdd=tempAdd;
    flags.stateSpectrum=true;
    if flags.onscreen==1;
        quer('c');
    end
    
end


%% 3. stateIRF
disp('Checking if requested report.stateIRF');
if isfield(report,'stateIRF')==false || isempty(report.stateIRF);
    disp('No States for IRF');
    flags.stateIRF=false;
else
    disp('States to for IRF');
    printcell(report.stateIRF(:));
    flags.stateIRF=true;
    [tempPos,tempAdd]=extractlevels(report.stateIRF,stateNames);
    report.stateIRFPos=tempPos;
    report.stateIRFPosAdd=tempAdd;
    if flags.onscreen==1;
        quer('c');
    end
    
end
%
%% 4. stateMom
disp('Checking if requested report.stateMom');
if isfield(report,'stateMom')==false || isempty(report.stateMom);
    disp('No States for Mom');
    flags.stateMom=true;
else
    disp('States to for Mom');
    printcell(report.stateMom(:));
    flags.stateMom=true;
    report=...
        setfield(report,'stateMomPos',cellposition(report.stateMom(:),stateNames,1));
    if flags.onscreen==1;
        quer('c');
    end
    
end
%
%% 5. subSamples report.sampleVec=sampleStru.sampleVec
disp('Checking if requested report.subSamples');
if isfield(report,'subSamples')==false || isempty(report.subSamples)==true;
    disp('No Subsamples to report in historical decomposition')
    flags.subSamples=false;
    return
else
    disp('Subsamples for Report')
    report.sampleVec=sampleStru.sampleVec;
    printcell(report.subSamples);
    flags.subSamples=true;
    report=sampleAssignments(report,1);
    flags.subSamples=true;
    
    if flags.onscreen==1;
        quer('c');
    end
    
end